package com.xd.common.util;

import java.text.DecimalFormat;
import java.util.*;

/**
 * 获取随机数
 */
public class RandomUtil {

    private static final Random random = new Random();

    private static final DecimalFormat fourdf = new DecimalFormat("0000");

    private static final DecimalFormat sixdf = new DecimalFormat("000000");

    //四位随机
    public static String getFourBitRandom() {
        return fourdf.format(random.nextInt(10000));
    }

    //六位随机数
    public static String getSixBitRandom() {
        return sixdf.format(random.nextInt(1000000));
    }

    /**
     * 生成随机数组
     *
     * @return
     */
    public static List<Boolean> getRandomBoolean(Integer counts, Integer totalSize) {
        counts = XkdUtil.ifNull(counts, totalSize);
        List<Boolean> list = new ArrayList<>();
        // 添加指定数量的1
        for (int i = 0; i < counts; i++) {
            list.add(false);
        }
        // 添加剩余的0
        for (int i = counts; i < totalSize; i++) {
            list.add(true);
        }
        // 打乱集合中元素的顺序
        Collections.shuffle(list);
        return list;
    }

    public static void main(String[] args) {
        List<Boolean> randomList = getRandomBoolean(7, 10);
        System.out.println(randomList);
        randomList.remove(0);
        System.out.println(randomList);
        randomList.remove(0);
        System.out.println(randomList);
        randomList.remove(0);
        System.out.println(randomList);
        randomList.remove(0);

    }
}
